package file_fragging;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/*
 * Solving File Fragmentation problem using Backtracking.
 */
class MainBT 
{
	public static void main(String [] args)
	{
		FileFragment ff = new FileFragment();
		ff.start();
	}
}

class FileFragment 
{
	Boolean done = false;
	
	void start()
	{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		try
		{
			// Read case input.
			int cases = Integer.parseInt(reader.readLine());
			
			for (int count = 0; count < cases; count++)
			{	
				reader.readLine();
				
				// Create a data structure to hold fragments.
				HashMap<String, Integer> list = new HashMap<String, Integer>();
				
				String input;
				
				Integer result = 1;
				
				// Reach an EOF or -1.
				while (!(input = reader.readLine()).equals(""))
				{
					// Retrieve value.
					Integer value = list.get(input);
					
					if (value != null)
					{
						result += value;
					} 
					else 
					{
						result = 1;
					}
					
					// Add value to input.
					list.put(input, result);
				}
				
				// Create a solution vector.
				String [] sArray = new String[2];
						
				// Start backtracking.
				fileFragBT(sArray, 0, list);
						
				if (done == false)
				System.out.println(sArray[0]);
				
				if (count > 0)
				System.out.println();
				
			}
		} 
		catch (IOException ex) 
		{
			ex.printStackTrace();
		}
	}
	
	void fileFragBT(String [] sArray, int counter, HashMap<String, Integer> fragList)
	{
		// Create candidate array.
		String [] candidates = new String[144];
		
		// Next position candidate count.
		int numOfCandidates;
		
		if (isSolution(sArray, fragList))
			processSolution(sArray);
		else
		{
			counter++;
			
			// Construct Candidates.
			numOfCandidates = constructCandidates(sArray, candidates, fragList, counter);
			
			for (int count = 0; count < numOfCandidates; count++)
			{
				sArray[counter - 1] = candidates[count];
				
				makeMove(sArray[counter - 1], fragList);
				
				fileFragBT(sArray, counter, fragList);
				
				unMakeMove(sArray[counter - 1], fragList);
				
				if (done == true)
					return;
			}
		}
	}
	
	boolean isSolution(String [] sArray, HashMap<String, Integer> fragList)
	{
		boolean isFilled = false;
		
		// If the solution is filled, proceed check.
		for (String value : sArray)
		{
			if (value != null)
				isFilled = true;
			else
				isFilled = false;
		}
		
		// Now verify that the binary string is a solution
		if (isFilled == true)
		{
			String binaryCode = sArray[0] + sArray[1];
			
			Set set = fragList.entrySet();
			
			Iterator iter = set.iterator();
			
			while (iter.hasNext())
			{
				Map.Entry me = (Map.Entry)iter.next();
				
				String binaryFragment = (String)me.getKey();
				
				if (!binaryCode.contains(binaryFragment))
				{
					return false;
				}
			}
		}
		
		// We're done.
		done = isFilled;
		
		return isFilled;
	}
	
	void processSolution(String [] sArray)
	{
		System.out.println(sArray[0] + sArray[1]);
	}
	
	int constructCandidates(String [] sArray, String [] candidates, HashMap<String, Integer> fragList, int k)
	{
		// Make sure that we are not going out of solution array bound.
		if (k > sArray.length)
		{
			return 0;
		}
		
		Set set = fragList.entrySet();
		
		Iterator iter = set.iterator();
		
		int counter = 0;
		
		while (iter.hasNext())
		{
			Map.Entry me = (Map.Entry)iter.next();
			
			String binaryFragment = (String)me.getKey();
			Integer count = (Integer)me.getValue();
			
			for (int i = 0; i < count; i++)
			{
				candidates[counter] = binaryFragment;
				counter++;
			}
		}
		
		return counter;
	}
	
	void makeMove(String binaryValue, HashMap<String, Integer> fragList)
	{
		// Retrieve value from key and determine how many remaining values are left.
		Integer value = fragList.get(binaryValue);
		
		if (value > 0)
		{
			value--;
			
			fragList.put(binaryValue, value);
		}
	}
	
	void unMakeMove(String binaryValue, HashMap<String, Integer> fragList)
	{
		Integer value = fragList.get(binaryValue);
		
		value++;
		
		fragList.put(binaryValue, value);
	}
}